package ifrn.agendaweb.servico;

import ifrn.agendaweb.jpa.CompromissoJPA;
import ifrn.agendaweb.modelo.Compromisso;
import ifrn.agendaweb.modelo.Usuario;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CompromissoServico {

	private CompromissoJPA compromissoPersistencia;

	@Autowired
	public void setServicoCompromisso(CompromissoJPA compromissoPersistencia) {
		this.compromissoPersistencia = compromissoPersistencia;
	}
	

	
	public void criar(Compromisso compromisso) throws ServicoException {
		
		compromissoPersistencia.criar(compromisso);
	}
	
	
	public void atualizar(Compromisso compromisso) throws ServicoException {
		
		compromissoPersistencia.atualizar(compromisso);
		
	}
	

	public Compromisso recuperarCompromisso(Compromisso compromisso) throws ServicoException{
		try {
			return compromissoPersistencia.recuperarPorId(compromisso);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServicoException(e.getMessage());
		}
	}
	
	public List<Compromisso> recuperarCompromisso(Usuario usuario) throws ServicoException{
		try {
			return compromissoPersistencia.recuperarCompromisso(usuario);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServicoException(e.getMessage());
		}
	}
	
	public List<Compromisso> recuperarTodosCompromissos(Usuario usuario) throws ServicoException{
		try {
			return compromissoPersistencia.recuperarTodos();
		} catch (Exception e) {
			throw new ServicoException(e.getMessage());
		}
	}


	public Compromisso recuperarCompromissoComContato(Compromisso compromisso) throws ServicoException {
		try {
			return compromissoPersistencia.recuperarPorIdComContato(compromisso);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServicoException(e.getMessage());
		}
	}



	public void deletar(Compromisso compromisso) throws ServicoException {
		try {
			compromissoPersistencia.deletar(compromisso);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServicoException(e.getMessage());
		}
	}
	

}
